﻿using System;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using System.Threading;
using Arch.Common.IoC;
using Microsoft.Practices.ServiceLocation;
using Microsoft.Practices.Unity;
using System.Reflection;

namespace Arch.Client.Silverlight.IoC
{
    public class BuildUpNavigationContentLoader : INavigationContentLoader
    {
        private static readonly PageResourceContentLoader DefaultPageContentLoader = new PageResourceContentLoader();

        public IAsyncResult BeginLoad(Uri targetUri, Uri currentUri, AsyncCallback userCallback, object asyncState)
        {
            return DefaultPageContentLoader.BeginLoad(targetUri, currentUri, userCallback, asyncState);
        }

        public bool CanLoad(Uri targetUri, Uri currentUri)
        {
            return DefaultPageContentLoader.CanLoad(targetUri, currentUri);
        }

        public void CancelLoad(IAsyncResult asyncResult)
        {
            DefaultPageContentLoader.CancelLoad(asyncResult);
        }

        public LoadResult EndLoad(IAsyncResult asyncResult)
        {
            var load = DefaultPageContentLoader.EndLoad(asyncResult);
            ServiceLocator.Current.BuildUp( load.LoadedContent);
            return load;
        }
    }
}